package com.wc.AlgoOJ_train.train1.c6.A608;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/1/10 21:55
 * @description 密码
 * http://43.138.190.70:8888/p/A608
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            if (isSafe(sc.next())) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }

    static boolean isSafe(String s) {
        char[] chs = s.toCharArray();
        int len = chs.length;
        if (len < 8 || len > 16) {
            return false;
        }
        boolean[] f = new boolean[5];
        int ans = 0;
        for (char ch : chs) {
            if (ans == 3) {
                return true;
            }
            if (Character.isUpperCase(ch)) {
                if (!f[1]) {
                    f[1] = true;
                    ans++;
                }
                continue;
            }
            if (Character.isLowerCase(ch)) {
                if (!f[2]) {
                    f[2] = true;
                    ans++;
                }
                continue;
            }
            if (Character.isDigit(ch)) {
                if (!f[3]) {
                    f[3] = true;
                    ans++;
                }

                continue;
            }
            if (is4(ch)) {
                if (!f[4]) {
                    f[4] = true;
                    ans++;
                }
                continue;
            }
            return false;
        }
        return ans >= 3;
    }

    static boolean is4(char ch) {
        return ch == '~' || ch == '!' || ch == '@' || ch == '#' || ch == '$' || ch == '%' || ch == '^';
    }
}
